//
//  GizWifiDevice+Phnix.m
//  PhnixHome
//
//  Created by Levy Xu on 2018/3/5.
//  Copyright © 2018年 Levy Xu. All rights reserved.
//

#import "GizWifiDevice+Phnix.h"
#import "GizConstant.h"

@implementation GizWifiDevice(Phnix)

-(BOOL)isAP736R {
    return [self.productKey isEqualToString:kProductKeyAP736R];
}

-(BOOL)isA725R {
    return [self.productKey isEqualToString:kProductKeyA725R];
}

-(NSString *)productSecret {
    if ([self isAP736R]) {
        return kProductSecretAP736R;
    } else if ([self isA725R]) {
        return kProductSecretA725R;
    }
    return @"";
}

-(UIImage *)displayImage {
    if ([self isA725R]) {
        return UIImageMake(@"product_waterpurifier1");
    } else if ([self isAP736R]) {
        return UIImageMake(@"product_waterpurifier2");
    }
    return nil;
}

-(NSString *)displayName {
    return [self deviceName];
}

-(NSString *)deviceName {
    if ([self isAP736R] || [self isA725R]) {
        return KIsBlankString(self.alias) ? self.productName : self.alias;
    }
    return @"";
}

-(NSString *)netStatusString {
    if (self.netStatus == GizDeviceOnline) {
        return NSLocalizedString(@"net_online", nil);
    } else if (self.netStatus == GizDeviceOffline) {
        return NSLocalizedString(@"net_offline", nil);
    } else if (self.netStatus == GizDeviceControlled) {
        return NSLocalizedString(@"net_controlled", nil);
    } else if (self.netStatus == GizDeviceUnavailable) {
        return NSLocalizedString(@"net_unavailable", nil);
    } else {
        return NSLocalizedString(@"unknown", nil);
    }
}

-(UIColor *)netStatusColor {
    if (self.netStatus == GizDeviceOnline) {
        return UIColorGreen;
    } else if (self.netStatus == GizDeviceOffline) {
        return UIColorRed;
    } else if (self.netStatus == GizDeviceControlled) {
        return UIColorGreen;
    } else if (self.netStatus == GizDeviceUnavailable) {
        return UIColorYellow;
    } else {
        return UIColorYellow;
    }
}

-(void)subscribe:(BOOL)subscribed {
    NSString *secret = [self productSecret];
    [self setSubscribe:secret subscribed:subscribed];
}

-(void)send:(NSDictionary<NSString *,id> *)data {
    if (self.netStatus != GizDeviceControlled) {
        [KKHUD showError:NSLocalizedString(@"tips_device_offline", nil)];
        return;
    }
    LOG(@"data %@", data);
    [self write:data withSN:1];
}

-(GizProductUI *)ui {
    return [GizProductUI mj_objectWithKeyValues:self.productUI];
}
@end
